home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / OscillatorListSpecifier.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  4.8 KB  |  142 lines  |  [TEXT/KAHL]

  1. /* OscillatorListSpecifier.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "OscillatorListSpecifier.h"
  31. #include "Memory.h"
  32. #include "OscillatorSpecifier.h"
  33.  
  34.  
  35. struct OscillatorListRec
  36.     {
  37.         long                                        NumOscillators;
  38.         struct OscillatorRec**    OscillatorArray;
  39.     };
  40.  
  41.  
  42. /* create a new array of oscillators */
  43. OscillatorListRec*            NewOscillatorListSpecifier(void)
  44.     {
  45.         OscillatorListRec*        OscList;
  46.  
  47.         OscList = (OscillatorListRec*)AllocPtrCanFail(sizeof(OscillatorListRec),
  48.             "OscillatorListRec");
  49.         if (OscList == NIL)
  50.             {
  51.              FailurePoint1:
  52.                 return NIL;
  53.             }
  54.         OscList->OscillatorArray = (struct OscillatorRec**)AllocPtrCanFail(0,
  55.             "struct OscillatorRec");
  56.         if (OscList->OscillatorArray == NIL)
  57.             {
  58.              FailurePoint2:
  59.                 ReleasePtr((char*)OscList);
  60.                 goto FailurePoint1;
  61.             }
  62.         OscList->NumOscillators = 0;
  63.         return OscList;
  64.     }
  65.  
  66.  
  67. /* dispose of oscillator list */
  68. void                                        DisposeOscillatorListSpecifier(OscillatorListRec* OscList)
  69.     {
  70.         long                                    Scan;
  71.  
  72.         CheckPtrExistence(OscList);
  73.         for (Scan = 0; Scan < OscList->NumOscillators; Scan += 1)
  74.             {
  75.                 PRNGCHK(OscList->OscillatorArray,&(OscList->OscillatorArray[Scan]),
  76.                     sizeof(OscList->OscillatorArray[Scan]));
  77.                 DisposeOscillatorSpecifier(OscList->OscillatorArray[Scan]);
  78.             }
  79.         ReleasePtr((char*)OscList->OscillatorArray);
  80.         ReleasePtr((char*)OscList);
  81.     }
  82.  
  83.  
  84. /* append a new oscillator */
  85. MyBoolean                                AppendOscillatorToList(OscillatorListRec* OscList,
  86.                                                     struct OscillatorRec* NewOscillator)
  87.     {
  88.         struct OscillatorRec**    NewList;
  89.  
  90.         CheckPtrExistence(OscList);
  91.         CheckPtrExistence(NewOscillator);
  92.         NewList = (struct OscillatorRec**)ResizePtr((char*)OscList->OscillatorArray,
  93.             sizeof(struct OscillatorRec*) * (1 + OscList->NumOscillators));
  94.         if (NewList == NIL)
  95.             {
  96.                 return False;
  97.             }
  98.         OscList->OscillatorArray = NewList;
  99.         OscList->OscillatorArray[OscList->NumOscillators] = NewOscillator;
  100.         OscList->NumOscillators += 1;
  101.         return True;
  102.     }
  103.  
  104.  
  105. /* get one of the oscillators from the list */
  106. struct OscillatorRec*        GetOscillatorFromList(OscillatorListRec* OscList, long Index)
  107.     {
  108.         CheckPtrExistence(OscList);
  109.         ERROR((Index < 0) || (Index >= OscList->NumOscillators),PRERR(ForceAbort,
  110.             "GetOscillatorFromList:  index is out of range"));
  111.         PRNGCHK(OscList->OscillatorArray,&(OscList->OscillatorArray[Index]),
  112.             sizeof(OscList->OscillatorArray[Index]));
  113.         return OscList->OscillatorArray[Index];
  114.     }
  115.  
  116.  
  117. /* find out how many oscillators there are in the list */
  118. long                                        GetOscillatorListLength(OscillatorListRec* OscList)
  119.     {
  120.         CheckPtrExistence(OscList);
  121.         return OscList->NumOscillators;
  122.     }
  123.  
  124.  
  125. /* resolve all modulation references.  returns False if it couldn't be done */
  126. MyBoolean                                ResolveOscillatorListModulators(OscillatorListRec* OscList)
  127.     {
  128.         long                                    Scan;
  129.  
  130.         CheckPtrExistence(OscList);
  131.         for (Scan = 0; Scan < OscList->NumOscillators; Scan += 1)
  132.             {
  133.                 PRNGCHK(OscList->OscillatorArray,&(OscList->OscillatorArray[Scan]),
  134.                     sizeof(OscList->OscillatorArray[Scan]));
  135.                 if (!ResolveOscillatorModulators(OscList->OscillatorArray[Scan],OscList))
  136.                     {
  137.                         return False;
  138.                     }
  139.             }
  140.         return True;
  141.     }
  142.